package com.vip.file.utils;

/**
 * 根据后缀判断是视频/图片
 */
public class FileTypeCheckerUtils {
    public static boolean isImage(String filename) {
        String[] imageExtensions = {"jpg", "jpeg", "png", "gif"};
        return arrayContains(imageExtensions, filename);
    }

    public static boolean isVideo(String filename) {
        String[] videoExtensions = {"mp4", "avi", "mov", "wmv"};
        return arrayContains(videoExtensions, filename);
    }

    public static boolean isMp3(String filename) {
        String[] videoExtensions = {"mp3","wav","flac","aac","m4a","ogg","wma","ape","alac"};
        return arrayContains(videoExtensions, filename);
    }

    public static boolean isTxt(String filename) {
        String[] videoExtensions = {"txt","xml","html","conf"};
        return arrayContains(videoExtensions, filename);
    }

    private static String getFileExtension(String filename) {
        int dotIndex = filename.lastIndexOf(".");
        return (dotIndex == -1) ? "" : filename.substring(dotIndex + 1).toLowerCase();
    }

    private static boolean arrayContains(String[] array, String target) {
        for (String item : array) {
            if (item.equals(target)) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        String filename = "example.jpg";
        System.out.println(isImage(filename)); // 输出: true

        filename = "example.mp4";
        System.out.println(isVideo(filename)); // 输出: true
    }
}